<template>
  <view class="home_category"
    ><navigator
      :url="`/pages/imgCategory/index?id=${item.id}`"
      class="cate_item"
      v-for="item in category"
      :key="item.id"
    >
      <img :src="item.cover" alt="" mode="aspectFill" />
      <view class="cate_name">{{ item.name }}</view></navigator
    >
  </view>
</template>

<script>
export default {
  data() {
    return {
      category: []
    };
  },
  methods: {
    async getList() {
      const res = await this.request("/image/v1/vertical/category");
      //console.log(res);

      if (res.code === 0) {
        this.category = res.res.category;
      }
    }
  },
  mounted() {
    uni.setNavigationBarTitle({ title: "分类" });
    this.getList();
  }
};
</script>

<style lang="scss">
.home_category {
  display: flex;
  flex-wrap: wrap;
  .cate_item {
    position: relative;
    width: 33.33333%;
    img {
      height: 240rpx;
    }

    .cate_name {
      display: flex;
      align-items: center;
      position: absolute;
      width: 100%;
      height: 50rpx;
      left: 0;
      bottom: 0;
      color: #fff;
      font-size: 40rpx;
      //css3 渐变
      background-image: linear-gradient(
        to right top,
        rgba(0, 0, 0, 0.2),
        rgba(0, 0, 0, 0)
      );
      padding-left: 20rpx;
    }
  }
}
</style>
